package com.example.back.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.back.bean.ShufflePoints;
import com.example.back.dao.ShufflePointsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RestController
public class ShufflePointsController {
    @Autowired
    ShufflePointsDao shufflePointsDao;

    @RequestMapping(value = "/getShufflePoints")
    List<ShufflePoints> getShuffle(){
        return shufflePointsDao.getShufflePointsValue();
    }

    @RequestMapping(value = "/updateShufflePoints")
    List<ShufflePoints> updateShuffle(long shuffle){
        shufflePointsDao.updateShufflePoints(shuffle);
        return shufflePointsDao.getShufflePointsValue();
    }

    @RequestMapping("updateShuffle")
    public String updateShuffle(long number,Integer groupId){
        if (groupId <= 0) {
            return "参数错误,请稍后再试";
        }
        ShufflePoints shufflePointList = shufflePointsDao.getShufflePointsByGroupId(groupId);
        if (shufflePointList!=null){
            shufflePointsDao.updateShufflePointByGroupId(number,groupId);
        }else{
            shufflePointsDao.insertShufflePoints(number,groupId);
        }
        return "修改成功,当前洗牌分为"+number;
    }
}
